#include<bits/stdc++.h>
using namespace std;
long long cnt,n,r;
int a[1000005];
bool book[1000005];
void dfs(int step,long long sum){
	if(cnt==r)return;
	if(step==n+1){
		cnt++;
		if(cnt==r)for(int i=1;i<=n;i++)cout<<a[i]<<" ";
		return;
	}
	for(int i=1;i<min((sum==0)? n+1:sum,n+1);i++){
		if(book[i]==0){
			book[i]=1;
			a[step]=i;
			dfs(step+1,sum+i);
			book[i]=0;
		}
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	freopen("permutation.in","r",stdin); 
	freopen("permutation.out","w",stdout); 
	cin>>n>>r;
	if(r==1){
		if(n==1)cout<<"1\n";
		else if(n==2)cout<<"2 1\n";
		else {
			cout<<"3 1 2 ";
			for(int i=4;i<=n;i++)cout<<i<<" ";
			cout<<"\n";
		}
		return 0;
	}else if(r==2){
		if(n==3)cout<<"3 2 1\n";
		else if(n==4)cout<<"3 2 1 4\n";
		else {
			cout<<"3 2 1 ";
			for(int i=4;i<=n-2;i++)cout<<i<<" ";
			cout<<n<<" "<<n-1<<"\n";
		}
		return 0;
	}
	dfs(1,0);
	return 0;
}
/*
3 1 2
3 1 2 4 5
*/

